package com.xyz;

import com.xyz.config.AppConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.xyz.service.UserService;

/**
 * spring 5程序启动类
 *
 * @author xqlee
 *
 */
public class Application {
    /** spring 依赖注入用户测试类 **/

    public static void main(String[] args) {
        // 创建spring 基于注解配置的容器
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        // 获取通过注解注入容器的UserService
        UserService userService = context.getBean(UserService.class);
        //UserService us = new UserService();
        // 调用userService的方法执行
        String message = userService.sayHello("xyz");
        // 输出结果
        System.out.println(message);

        UserService userService1 = new UserService("用户服务1",1);
        System.out.println(userService1+userService1.sayHello("spring"));
        // 关闭容器,释放JVM资源
        context.close();
    }
}